package edu.suda.xsap.mapper;

import edu.suda.xsap.entity.MemberCard;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface MemberCardMapper {
    void save(MemberCard card);
    void update(MemberCard card);
    void delete(Integer id);
    MemberCard findById(Integer id);
    MemberCard findByName(String name);
    List<MemberCard> findAll();

    List<MemberCard> findByCardIds(@Param("cardIds") List<Integer> cardIds);

    @Select("SELECT c.name AS name, COUNT(*) AS value " +
            "FROM t_member_bind_record r " +
            "JOIN t_member_card c ON r.card_id = c.id " +
            "GROUP BY c.name")
    List<Map<String, Object>> findCardTypeStatistics();
}
